package org.hackystat.devcathlon.ui.page.teams;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.hackystat.devcathlon.engine.team.TeamManager;
import org.hackystat.devcathlon.engine.user.User;

/**
 * Provide Session state for the Teams area of the Devcathlon application. 
 * An instance of this is automatically created in DevcathlonSession. 
 * Access using DevcathlonSession.get().getTeamsSession().
 * @author Philip Johnson
 */
public class TeamsSession implements Serializable {
  
  /** Supports serialization. */
  private static final long serialVersionUID = 1L;
  /** The current selected team. */
  private String selectedTeam = "";
  /** The project of the selected team. */
  private String projectName = "";
  /** The file path to the team logo. */
  private String teamLogoPath = "";  
  /** The owner of the selected team. */    
  private User owner;
  /** The list of members of the selected team. */
  private List<User> members = new ArrayList<User>();
  /** The list of members who were invited to the selected team. */
  private List<User> invited = new ArrayList<User>();  
  /** The description of the selected team. */
  private String description = "";
  
  
  /**
   * Support session state for the Teams page and subpages. 
   */
  public TeamsSession() {
    //Nothing yet
  }
  
  /**
   * Sets the current selected team to the one specified. 
   * @param selected The team to set to.
   */
  public void setSelectedTeam (String selected) {
    this.selectedTeam = selected;
    this.members = new ArrayList<User>(TeamManager.getInstance().getTeam(selected).getMembers());
    this.invited = new ArrayList<User>(TeamManager.getInstance().getTeam(selected).getInvited());
    this.owner = TeamManager.getInstance().getTeam(selected).getOwner();
    this.projectName = TeamManager.getInstance().getTeam(selected).getProjectName();
    this.description = TeamManager.getInstance().getTeam(selected).getDescription();
    this.teamLogoPath = TeamManager.getInstance().getTeam(selected).getTeamLogoPath();
  }
  
  /**
   * Sets selected team values to all blank fields.  
   * Basically used to prevent null pointers on pages if no team is selected.
   */
  public void clearSelectedTeam () {
    this.selectedTeam = "";
    this.members = new ArrayList<User>();
    this.invited = new ArrayList<User>();
    this.owner = null;
    this.projectName = "";
    this.description = "";
  }
  
  /**
   * Gets the last selected team.
   * @return The last selected team.
   */
  public String getSelectedTeam () {
    return this.selectedTeam;
  }
  
  /** 
   * Returns the list of members of the selected team.
   * @return The list of members.
   */
  public List<User> getMembers() {
    return this.members;
  }
  
  /** 
   * Returns the list of invited members of the selected team.
   * @return The list of members.
   */
  public List<User> getInvited() {
    return this.invited;
  }
  
  /** 
   * Returns the owner of the selected team.
   * @return The owner.
   */
  public User getOwner() {
    return this.owner;
  }

  /**
   * Returns the project of the selected team.
   * @return The project name.
   */
  public String getProjectName() {
    return this.projectName;
  }
  
  /**
   * Returns the description of the selected team.
   * @return The description.
   */
  public String getDescription() {
    return this.description;
  }
  
  /** 
   * Returns the file path to the team logo of the selected team.
   * @return The file path.
   */
  public String getTeamLogoPath() {
    return this.teamLogoPath;
  }
}
